package com.syni.mdd.yhd.common.all.listen.focus;

import com.alibaba.fastjson.JSON;
import com.syni.mdd.yhd.common.all.constants.AuroraPushCode;
import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.dto.requestDto.groupChart.GroupChatReDto;
import com.syni.mdd.yhd.common.all.entity.*;
import com.syni.mdd.yhd.common.all.entity.groupChat.BmsDxGroupChat;
import com.syni.mdd.yhd.common.all.service.*;
import com.syni.mdd.sjb.common.component.utils.common.utils.BeanUtils;
import com.syni.mdd.sjb.common.component.utils.common.utils.DateTimeUtils;
import com.syni.mdd.yhd.common.all.utils.StringUtils;
import com.syni.mdd.yhd.common.all.utils.TokenManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * @className OrderListener
 * @description TOO
 * @Author cfx
 * @DATE 2019/8/8 15:46
 * @VERSION 1.0
 **/
@Component
public class BusinessFocusListener implements ApplicationListener<BusinessFocusEvent> {
    private final Logger log = LoggerFactory.getLogger(getClass());


    @Autowired
    BmsDxGroupChatService bmsDxGroupChatService;

    @Override
    @Async
    public void onApplicationEvent(BusinessFocusEvent businessFocusEvent) {
        log.info("......................关注店铺...................");
        BmsBusiness business = businessFocusEvent.getBmsBusiness();
        Integer userId = businessFocusEvent.getUserId();
        //关注成功后，如果该商家有群，进入商家群
        List<BmsDxGroupChat> bmsDxGroupChats = bmsDxGroupChatService.getBaseDao().findByBusinessIdAndIsDelete(business.getId(),Constants.COMMON_FLAG_FALSE_INT);
        if(bmsDxGroupChats != null && bmsDxGroupChats.size() > 0){
            GroupChatReDto groupChatReDto = new GroupChatReDto();
            groupChatReDto.setBusinessId(business.getId());
            groupChatReDto.setUserId(userId.toString());
            bmsDxGroupChatService.userJoinGroup(groupChatReDto);
        }
    }
}
